<template>
	<view class="content">
		<view class="remark">备注：
			“已发放”指：触发“发放”按钮次数。
			“领取数”指：用户实际领取的次数（用户
			打开页面意味着领取）</view>
		<view class="toolKit-btn"><u-button type="primary" text="仅发放工具包" color="#d17060" @click="handleShare"></u-button></view>
		<view class="classify" >
			<u-tabs :list="classifyList" @click="handleChange" :activeStyle="{color:'#181818'}"
				:inactiveStyle="{color:'#8b8b8b'}" lineColor="#b95f62" :current="curt"></u-tabs>
		</view>
		<view class="list" v-for="(item,index) in list" :key="index">
			<view class="top-box">
				<view class="code">激活码</view>
				<view class="title-box">
					<view class="title">{{item.project_name}}</view>
					<view class="date">{{item.days}}</view>
				</view>
				<view class="num">
					<view><text>本轮总共</text>{{item.allocation_num}}个/已发放{{item.grant_num}}个/领取数{{item.receive_num}}人</view>
					<view>可用{{Number(item.allocation_num)-Number(item.grant_num)}}个</view>
				</view>
			</view>
			<view class="bot-box">
				<view class="price">
					<view>总发放:{{item.grant_total_num}}个</view>
					<view>售价:{{item.price}}元</view>
					<view>总领取数:{{item.receive_total_num}}人</view>
				</view>
				<view class="grant" @click="handleGrant(item)">发放</view>
			</view>
		</view>
		<!-- 发放弹框 -->
		<GrantModel ref="grantModel" @getShareData="getShareData" @getPrice="getPrice"/>
	</view>
</template>

<script>
	import {activeType,projectList,shareCode} from '@/api/activationCode.js'
	import GrantModel from './GrantModel.vue'
	export default {
		components: {
			GrantModel
		},
		data() {
			return {
				classifyList: [],
				list:[],
				type:null,
				shareData:null,
				price:null,
				curt:null
			}
		},
		onLoad() {
			this.getClassifyList()
		},
		onShow() {			
			uni.hideTabBar()			
			this.$refs.grantModel.closeModel()
			
			
		},
		computed: {
			activeSystemData() {
				return this.$store.state.activeSystemData
			},
		
		},
		onShareAppMessage(res) {
			
			if (res.from === 'button') {
				const data = res.target.dataset.obj
				this.shareNum()
				// 来自页面内转发按钮
				return {
					title: `${data.name} ${data.days}激活码`,
					path: `/pages/toolKit/toolKit?projectId=${data.active_project_id}&code=${data.code}`,
					imageUrl: this.activeSystemData.qun_share_image
				};
				
			}else{
				return {
					imageUrl: this.activeSystemData.fama_share_image
				}
			}
		},
		methods: {
			async getShareData(data){
				// await shareCode(data)
				this.shareData = data
			},
			getPrice(data){
				this.price=data
			},
			async shareNum(){
				 await shareCode({project_id:this.shareData.active_project_id,real_price:this.price})
			},
			async getClassifyList(){
				const {data}=await activeType()
				this.classifyList=data
				this.curt=0
				if(this.classifyList.length>0){
					this.type=this.classifyList[0].type
					this.getList()
				}
			},
			async getList(){
				const {data}=await projectList({type:this.type})
				this.list=data
			},
			handleShare(){
				uni.navigateTo({
					url:'/pages/toolKit/toolKit'
				})
			},
			//发放
			handleGrant(data){
				this.$refs.grantModel.setModel(data.project_id)
				this.getList()
			},
			handleChange(e) {
				this.type=e.type
				this.getList()
			},
			
		}
	}
</script>

<style scoped lang="scss">
	.content {
		padding: 32rpx;
		box-sizing: border-box;
		background: #f0f0f0;
		min-height: 100vh;

		.list {
			margin-top: 24rpx;
			background: #fff;
			border-radius: 18rpx;
			position: relative;

			.bot-box {
				border-top: 1px dashed #eeeeeb;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 24rpx;
				box-sizing: border-box;

				.price {
					font-size: 28rpx;
					color: #6f6f6f;
					display: flex;
					align-items: center;

					view {
						margin-right: 8rpx;
					}
				}

				.grant {
					width: 120rpx;
					height: 55rpx;
					background: #559768;
					font-size: 26rpx;
					color: #fff;
					display: flex;
					align-items: center;
					justify-content: center;
					border-radius: 16rpx;
					letter-spacing: 4rpx;

				}
			}

			.top-box {
				padding: 24rpx;
				box-sizing: border-box;

				.num {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 28rpx;
					margin-top: 24rpx;
					color: #484848;

					text {
						color: #6b6b6b;
					}
				}

				.title-box {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 32rpx;

					s .title {
						font-size: 32rpx;
						font-weight: 800;
						display: flex;
						flex: 1;
						margin-right: 24rpx;
					}

					.date {
						font-size: 32rpx;
						font-weight: 800;
						color: #d27160;
					}
				}

				.code {
					font-size: 24rpx;
					color: #fff;
					background: #d27160;
					border-radius: 18rpx 0 18rpx 0;
					position: absolute;
					left: 0;
					top: 0;
					padding: 8rpx 20rpx;
				}
			}

		}

		.remark {
			font-size: 26rpx;
			color: #666;
		}

		.toolKit-btn {
			width: 300rpx;
			margin: 24rpx auto;

			/deep/ .u-button {
				border-radius: 18rpx;
			}
		}
	}
</style>